package base.多线程.扩展JUC.温度传感器类;

import java.sql.Time;
import java.util.Random;
import java.util.concurrent.TimeUnit;

public class TemperatureSensor implements Runnable{
    private volatile int temperture = 24;
    private String type;


    public synchronized int getTemperture() {
        return temperture;
    }

    public synchronized void setTemperture(int temperture) {
        this.temperture = temperture;
    }

    @Override
    public void run() {
       synchronized (TemperatureSensor.class){
           if (this.temperture > 60){
               System.out.println("高温提醒！！！");
           }
           Random r = new Random();
           int i = r.nextInt(3);
           this.setTemperture(temperture += i);
       }
    }
}
